package com.ittsang.controller;

import com.ittsang.dto.PageDTO;
import com.ittsang.dto.R;
import com.ittsang.dto.RaceDTO;
import com.ittsang.service.RaceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

@RestController
@RequestMapping("/race")
public class RaceController {

    @Resource
    private RaceService raceService;

    /**
     *  获取比赛
     * @param pageDTO
     * @return
     */
    @PostMapping("/getRace")
    public R getRace(@RequestBody PageDTO pageDTO) {
        return raceService.getAllRace(pageDTO);
    }

    /**
     *  管理员获取自己部门比赛
     * @param pageDTO
     * @return
     */
    @PostMapping("/getAllAuditRace")
    public R getAllRace(@RequestBody PageDTO pageDTO) {
        return raceService.getAllAuditRace(pageDTO);
    }

    /**
     *  添加普通比赛，没人员限制
     * @param raceDTO
     * @return
     */
    @PostMapping("/insertRace")
    public R insertRace(@RequestBody RaceDTO raceDTO) {
        return raceService.insertRace(raceDTO);
    }

    /**
     *  添加秒杀比赛，有人员限制
     * @param raceDTO
     * @return
     */
    @PostMapping("/insertLimitRace")
    public R insertLimitRace(@RequestBody RaceDTO raceDTO) {
        return raceService.insertLimitRace(raceDTO);
    }

    /**
     *  参加人数限制比赛
     * @param raceId
     * @return
     */
    @GetMapping("/kill")
    public R killRace(@RequestParam("raceId") Integer raceId) throws ParseException {
        return raceService.killRace(raceId);
    }

    /**
     *  参加普通比赛
     * @param raceId
     * @return
     */
    @GetMapping("/joinRace")
    public R joinRace(@RequestParam("raceId") Integer raceId) {
        return raceService.joinRace(raceId);
    }

    /**
     *  根据id获取比赛详情
     * @param raceId
     * @return
     */
    @GetMapping("/getRaceInfoById")
    public R getRaceInfoById(@RequestParam("raceId") Integer raceId) {
        return raceService.getRaceInfoById(raceId);
    }

    /**
     *  修改比赛
     * @param pageDTO
     * @return
     */
    public R updateRace(PageDTO pageDTO) {
        return null;
    }

    /**
     *  删除比赛
     * @param pageDTO
     * @return
     */
    public R deletedRace(PageDTO pageDTO) {
        return null;
    }

    /**
     *  审核通过比赛
     * @param raceId
     * @return
     */
    @GetMapping("/reviewedRace")
    public R reviewedRace(@RequestParam("raceId") Integer raceId) {
        return raceService.reviewedRace(raceId);
    }

    /**
     *  审核不通过比赛
     * @param raceId
     * @return
     */
    @GetMapping("/reviewedNoRace")
    public R reviewedNoRace(@RequestParam("raceId") Integer raceId) {
        return raceService.reviewedNoRace(raceId);
    }


    /**
     *  获取比赛分类
     * @return
     */
    @GetMapping("/getRaceType")
    public R getRaceType() {
        return raceService.getRaceType();
    }

    /**
     *  根据类型id获取比赛信息
     * @param pageDTO
     * @return
     */
    @PostMapping("/getRaceById")
    public R getRaceById(@RequestBody PageDTO pageDTO) {
        return raceService.getRaceById(pageDTO);
    }

    /**
     *  用户退出比赛
     * @param raceId
     * @return
     */
    @GetMapping("/quitRaceById")
    public R quitRaceById(@RequestParam("raceId") Integer raceId) {
        return raceService.quitRaceById(raceId);
    }

}
